package com.xhui.vimarket.zkplus.zul.attr.evt.rtime;

import java.util.ArrayList;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.metainfo.ComponentInfo;

import com.xhui.crm.common.util.springplus.Spring;
import com.xhui.crm.common.util.string.StrUtil;com.xhui.vimarket.zkplusui.vimarket.zkplus.zul.attrcom.xhui.vimarket.zkplusrt com.xhui.vimarket.zkplus.zul.attr.acom.xhui.vimarket.zkplustf;
import com.xhui.vimarket.zkpcom.xhui.vimarket.zkplusan.AttrInst;
import com.xhui.vicom.xhui.vimarket.zkplusul.attr.mod.AttrComp;
import com.xhui.com.xhui.vimarket.zkplus.zul.attr.mod.AttrCompFactory;
impocom.xhui.vimarket.zkplusarket.zkplus.zul.attr.mod.AttrCompUtil;com.xhui.vimarket.zkplusui.vimarket.zkplus.zul.attr.rule.AttrCheckRight;
import com.xhui.vimarkecom.xhui.vimarket.zkplustr.util.AttrConstants;

/**
 * @版权：福富软件 版权所有 (c) 2010.
 * @文件：com.xhui.vimarket.zkplus.zul.attr.evt.AttrCheckboxComposer.java
 * @所含类：
 * @author: wuyx
 * @version: V1.0
 * @see:
 * @创建日期：2010-12-20
 * @功能说明：变化事件处理
 * @修改记录： =============================================================<br>
 *        日期:2010-12-20 创建
 *        =============================================================<br>
 */
abstract class AttrRtimeSelectComposer extends AttrRtimeBaseComposer {
    
    /**
     * serialVersionUID.
     */
    private static final long serialVersionUID = 4579587521568091904L;
    
    @Override
    public ComponentInfo doBeforeCompose(final Page page, final Component comp,
        final ComponentInfo info) {
        return info;
    }
    
    @Override
    public void doAfterCompose(final Component comp) throws Exception {
        super.doAfterCompose(comp);
    }
    
    /**
     * onSelect.
     */
    public void onSelect() {
        // attr 控件根
        final Component attrComp = this.getRootComp();
        // attr 顶级控件
        final AttrExt attrExt = AttrCompUtil.getAttrExtComp(attrComp);
        AttrComp attrCompAda = AttrCompFactory.getInstByComponent(attrComp);
        // 否则直接触本控件设置值
        final ArrayList<AttrInst> retList = attrCompAda.getValue(attrExt, attrComp);
        for (AttrInst attrInst : retList) {
            if (attrInst.isCheckRight()) {
                AttrCheckRight acr = (AttrCheckRight) Spring.getBean("attrCheckRight");
                AttrEntityIntf aei = (AttrEntityIntf) Spring.getBean("attrEntityIntf");
                //获取实例对象的规格ID
                String cId = "";
                if (aei != null) {
                    if (aei.getEntityClassId(attrExt.getEntity()) != null 
                        && aei.getEntityClassId(attrExt.getEntity()) != 0) {
                        cId = StrUtil.strnull(aei.getEntityClassId(attrExt.getEntity()));
                    }
                }
                //判断是否有权限
                if (acr != null) {
                    if (!acr.hasRight(cId + AttrConstants.CHECK_RIGHT_PREFIX_VALUE 
                        + attrInst.getAttrId() + "" + attrInst.getParam1())) {
                        //值还原成前一次选择的值
                        attrExt.refreshAttrComp(attrComp);
                        //相应的提示信息
                        throw new WrongValueException(this.self, "该工号没有选择【" + attrInst.getAttrName() + "】的权限！");
                    }
                }
            }
        }
        super.onSetVal();
    }
    
}
